package xiaoyang.controller.back;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import xiaoyang.Constants;
import xiaoyang.pojo.Backend_user;
import xiaoyang.service.Backend_userService;
import xiaoyang.service.Dev_userService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class login {
    @Resource
    private Dev_userService devUserService;
    @Resource
    private Backend_userService backendUserService;
   /* @RequestMapping("loginDev")
    public String loginDev(@RequestParam String devCode, @RequestParam String devPassword, HttpSession session){
        Dev_user dev_user = devUserService.loginDev(devCode, devPassword);
        if (dev_user!=null){
            session.setAttribute("devName",dev_user);
            return "redirect:/";
        }else {
            return "/login";
        }
    }*/
    @RequestMapping("/tobackBack")
    public String tobackBack(){
        return "backendLogin";
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "index";
    }
    @RequestMapping("/loginBack")
    public String loginBack(@RequestParam String userCode, @RequestParam  String userPassword, HttpSession session, Model model){
        Backend_user backend_user=null;
        try{
             backend_user = backendUserService.loginBackend(userCode, userPassword);
        }catch (Exception e){
            e.printStackTrace();
        }

        if (backend_user!=null){
            session.setAttribute(Constants.USER_SESSION,backend_user);
            return "indexadmin";
        }else {
            throw new RuntimeException("账号或者密码不正确");
        }
        }

}
